﻿namespace BM.Tools.WebControls.MForm.Controls.Validators
{
    using System.Text;
    using System.Web.UI;

    /// <summary>
    /// An abstract class for keeping information about validation errors in the MForm tree.
    /// </summary>
    public abstract class ErrorCause
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ErrorCause"/> class.
        /// </summary>
        /// <param name="errorControl">
        /// The error control.
        /// </param>
        protected ErrorCause(IXmlEditor errorControl)
        {
            ErrorControl = errorControl;
        }

        /// <summary>
        /// Gets ErrorControl.
        /// </summary>
        public IXmlEditor ErrorControl
        {
            get;
            private set;
        }        

        /// <summary>
        /// Gets the full text to be displayed about the error cause.
        /// </summary>
        public string ErrorText
        {
            get
            {
                var builder = new StringBuilder();
                builder.Append(@"<a href=""#"" onclick=""return BM.ValidationError.go('");
                builder.Append((ErrorControl as Control).ClientID);
                builder.Append(@"')"" />");
                builder.Append(ErrorControlName);
                builder.Append(@"</a>: ");
                builder.Append(ErrorMessage);
                return builder.ToString();
            }
        }

        /// <summary>
        /// Gets the message about the occurring error.
        /// </summary>
        protected abstract string ErrorMessage
        {
            get;
        }

        /// <summary>
        /// Gets the name of the error control
        /// </summary>
        protected abstract string ErrorControlName
        {
            get;
        }
    }
}
